package com.link.base.base.product.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.link.base.base.product.model.ProdPackage;
import com.link.base.base.product.service.ProdPackageService;
import com.link.core.basic.service.BasicServiceException;
import com.link.core.basic.service.ServiceException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import com.link.core.basic.controller.BasicController;
import com.link.core.basic.service.BasicService;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 路江
 * @date 2018-09-26
 * @comments 产品组合
 */
@Controller
@RequestMapping("/link/prodPackage")
public class ProdPackageController extends BasicController<ProdPackage> {
    private static final Logger logger = LogManager.getLogger(ProdPackageController.class);
    @Resource
    private ProdPackageService prodPackageService;

    @Override
    public BasicService<ProdPackage> getBasicService() throws Exception {
        return prodPackageService;
    }

    @RequestMapping({"/batchDelete"})
    @ResponseBody
    public Map<String, Object> batchDelete(@RequestBody List<ProdPackage> list, HttpSession session,
                                           HttpServletRequest request, HttpServletResponse response) {
        HashMap result = new HashMap();

        try {
            ProdPackage entity = null;

            for (int i = 0; list != null && i < list.size(); ++i) {
                entity = (ProdPackage)list.get(i);
                this.beforDelete(entity, request);
                this.checkData(entity, request);
                if (!this.checkExistDataCache("base", session, entity)) {
                    throw new ServiceException("PUBLIC-031");
                }
            }

            this.getBasicService().batchDelete(list);
            result.put("success", true);
        } catch (BasicServiceException var8) {
            logger.error("BasicController捕获异常: ", var8);
            result.put("success", false);
            result.put("result", var8.getMessage());
            result.put("detailMessage", var8.getDetailMessage());
        } catch (Exception var9) {
            logger.error("BasicController捕获异常: ", var9);
            result.put("success", false);
            result.put("result", var9.getMessage());
        }

        return result;
    }
}
